<template>
	<view class="page">
		<view class="body"> 
			<image src="@/static/images/login_bg.png" mode="widthFix" class="body-bg"></image>

			<view class="login-wrap">
				<view class="login-form active">					 
					
					<view class="wechat-login-btn">
						<view v-if="!isAgree" class="mask-btn" @click="checkAuth"></view>
						<button open-type="getPhoneNumber" class="btn wechat" @getphonenumber="wxGetPhoneNumber">手机号快捷登录</button>
						<!-- <button class='btn wechat' @click="login"></button> -->
					</view> 
					<!-- <view class="btn">微信一键登录</view> -->
					
					<view class="agree-bar">						
						<label class="re-pw-text" @click="setAgree">
							<text v-if="!isAgree" class="icon iconfont f-s34 m-r1 f-grey">&#xe6a6;</text>
							<text v-else class="icon iconfont f-s34 m-r1 f-green">&#xe604;</text>	
							<text>同意并阅读</text>							
						</label>
						<navigator open-type="navigate" url="/package_member/authorization/authorization?type=2" hover-class="none">《隐私协议及用户服务协议》</navigator>
					</view> 			 
					
				</view>
			</view>
			 
		</view> 
		<c-privacy-popup v-if="isShowAuth" :auth="isShowAuth" @handleDisagree="handleDisagree" @handleAgree="handleAgree"></c-privacy-popup>
	</view>
</template>

<script>
	import {
		replaceStr,
		checkPhone
	} from '@/common/util.js'
	import {login} from '@/common/login.js'
	import Timer from '@/common/timer.js'
	import {
		HTTP_REQUEST_URL
	} from '@/config.js'
	export default {
		name: '',
		data() {
			return {
				isShowAuth:false,
				isAgree:false,
				// isRemberPw: true,
				// password: '' || uni.getStorageSync('password'),
				// user_name: '' || uni.getStorageSync('user_name'),
				// new_pw: '',
				// new_pw1: '',
				// phone: '',
				// replace_phone: '',
				// phone_code: '',
				// phone_code_type: '4', // 0/空 密码登录   1 找回密码  2 重置密码  3 登录  4 登录/注册
				// count_time_text: '获取验证码',
				// isSentCode: true,
				// isStop: true,
				// isMb: true,
				// isWechat:true,
				// flag: {
				// 	isFullPage: false,
				// 	isCheckPhone: false,
				// 	isRestPassword: false
				// },
				// isAgree: false,
				// timer: null,
				// userInfo: {},
				// backType: ''

			}
		},
		async onLoad(params) {
			// this.replace_phone = replaceStr(this.user_name, 3, '****')
			// if (params.backType) {
			// 	this.backType = params.backType;
			// }
		},
		async onShow() {},
		methods: {
			
			checkAuth(){
				if(!this.isAgree){
					this.isShowAuth=true; 
				}else{
					this.isAgree=!this.isAgree;				
				}							
			},			 
			
			// 不同意授权
			handleDisagree(){
				this.isShowAuth=false;
				this.isAgree=false;
			},
			
			// 同意授权
			handleAgree(){
				this.isShowAuth=false;
				this.isAgree=true; 
			},
			
			setAgree(){ 	
				this.checkAuth();
			},
			
			wxGetPhoneNumber(e){
				let _this=this;
				console.log(e) 
				uni.login({
					provider: "weixin",
					async success(res_code) {
						console.log(res_code)
						uni.request({
							url: HTTP_REQUEST_URL + '/user/login',
							data: { 
								login_code:res_code.code,
								mobile_code:e.detail.code
							},
							method: 'post',
							header: {
								"Content-Type": "application/x-www-form-urlencoded",
								'Cookie': []
							},
							dataType: 'json',
							async success(p) {  
								if(p.data.code==0){
									uni.showToast({
										icon:'success',
										mask:true,
										title:p.data.msg
									})
									uni.setStorage({
										key:'token',
										data:p.data.data.token
									})		 
									uni.reLaunch({
										url:'/pages/index/index'
									})
									_this.$store.dispatch('getUserInfo')
								}else if(p.data.code==1004){
									uni.showToast({
										icon:'error',
										mask:true,
										title:p.data.msg
									})									
								}
								 
							}  
						}); 	 
					}
				})
				
				
				return 
				uni.getUserProfile({
					desc: '用户名',
					success: async function(res) {
						console.log('weixing',res)
						
				
					}
				}) 
			},

			 

			// 弹窗
			showPopup: function(t, n) {
				if (t == 'show') {
					this.flag.isFullPage = true;
					this.flag[n] = true;
				} else if (t == 'hide') {
					for (let i in this.flag) {
						this.flag[i] = false;
					}
				}
			},


		},
		onUnload() {
			if (this.timer) {
				this.timer.stop();
			}
		},
		computed: {

		},
		components: {

		},
	}
</script>

<style lang="less" scoped>
	.page,
	page ,.body{
		height: 100%;		
		position: relative;
		overflow: hidden;
	}
	.body-bg{
		position: absolute;
		left:0;
		top:0;
		width: 100%; 
	}
	.close-btn{
		position: fixed;
		right:20rpx;
		top:80rpx;
		z-index: 100;
		color:#fff;
	} 

	.login-wechat{
		width: 120rpx;
		margin: 0 auto;
		image{
			width: 100%;
		}
	}
	.login-type-btn{
		position: fixed;
		bottom:50rpx;
		width: 100%;
		text-align: center;
		font-size: 28rpx;
		color:#fff;
	}
	.login-wrap {
		position: relative;
		z-index: 100;
		padding-top: 50%;
		.active {
			display: block;
		}
	}

	.login-form {
		@h: 90rpx;
		width: 90%;
		margin: 0 auto 40rpx;
		display: none;

		.item {
			display: flex;
			width: 90%;
			margin: 0 auto 40rpx;
			height: @h;
			line-height: @h;
			background: rgba(255, 255, 255, .4);
			border-radius: 10rpx;

			.icon {
				width: @h;
				height: @h;
				text-align: center;
				line-height: @h;
				flex-shrink: 0;

				image {
					width: 50%;
					vertical-align: middle;
				}
			}

			input {
				flex-grow: 2;
				height: @h;
				line-height: @h;
				font-size: 30rpx;
				color: #fff;
			}

			.get-code-btn {
				width: 200rpx;
				margin-right: 10rpx;
				color: #fff;
				font-size: 30rpx;
				text-align: center;
			}
		}

		.wechat-login-btn {
			position: relative;
			width: 90%;
			height: @h;
			margin: 0 auto 20rpx;
			.mask-btn{
				position: absolute;
				left:0;
				top:0;
				z-index: 1;
				width: 100%;
				height: 100%; 
			}
			.btn{				
				text-align: center;				
				line-height: @h;
				background: #00aa7f;
				border-radius: 10rpx;
				color: #fff;
				font-size: 34rpx;
			}
			
		} 
	}

	.re-pw {
		display: flex;
		height: 40rpx;
		line-height: 40rpx;

		radio {
			position: relative;
			transform: scale(0.7);
			color: #FFFFFF;
		}

		.active {
			color: #FFFFFF;
		}

		.re-pw-text {
			font-size: 32rpx;
			color: #ffffff;
		}
	}

	.link-bar {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 5% 50rpx;

		.find-pw-text {
			height: 40rpx;
			line-height: 40rpx;
			font-size: 30rpx;
			color: #fff;
		}

	}
	
	.register-text{
		padding: 0 5% ;
		margin-bottom: 100rpx;
		text-align: right;
		font-size: 30rpx;
		color:#fff;
	}

	.agree-bar {
		display: flex;
		align-items: center;
		padding: 0 5% 50rpx;
		color: #666;
		font-size: 28rpx;

		radio {
			transform: scale(.7);
			color: #ff9600
		}

		.re-pw-text {
			display: flex;
			align-items: center;
		}

		navigator {
			color: #ff9600;
		}
	}

	.agreerule {
		display: flex;
		text-align: center;
		justify-content: center;
		position: fixed;
		left: 0;
		width: 100%;
		bottom: 40rpx;

		.icon {
			margin-right: 10rpx;
			color: #E5E5E5;
		}

		.active {
			color: #000;
		}

		.agreerule-text {
			display: flex;
			font-size: 30rpx;
			color: #999;

			navigator {
				color: #f00;
			}
		}
	}

	.code-bar {
		display: flex;
		height: 80rpx;
		border: 1rpx solid #eee;
		border-radius: 15rpx;
		margin-bottom: 40rpx;

		input {
			width: 90%;
			height: 80rpx;
			line-height: 80rpx;
			padding: 0 10rpx;
			font-size: 30rpx;
		}

		.get-code-btn {
			flex-shrink: 0;
			width: 35%;
			line-height: 80rpx;
			text-align: center;
			font-size: 30rpx;
			color: #09f;
		}
	}

	.get-code-popup {
		.phone-text {
			margin-bottom: 30rpx;
			color: #666;
			font-size: 30rpx;
		}

		.code-comfirm-btn {
			height: 70rpx;
			line-height: 70rpx;
			margin: 0 auto;
			background: #ddd;
			border-radius: 8rpx;
			color: #999;
			text-align: center;
			font-size: 30rpx;
		}

		.active {
			background: linear-gradient(#e96b5c, #ce3c2f);
			color: #fff;
		}
	}
</style>
